********
use data, clear
global controls PGDP PGDP_2 PDEN INDS CONS GOV Lnrain Lnsun




***Table 2 The statistical description of the variables
tabstat CEI NPC PGDP PDEN INDS CONS GOV Lnrain Lnsun, stats(N mean sd) c(s)
  
  sum2docx CEI NPC PGDP PDEN INDS CONS GOV Lnrain Lnsun using Table2.docx, replace stats(N mean(%9.4f) sd(%9.4f)) title("Table 2 The statistical description of the variables")
  
  
***Table 3 The results of the baseline model
xtset cid year

  xtreg CEI NPC PGDP PGDP_2 PDEN INDS CONS GOV yr*,fe cluster(cid)
    est store m1 
  xtreg CEI NPC $controls yr*, fe cluster(cid)
    est store m2
   esttab m1 m2 , b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr*) star(* 0.1 ** 0.05 *** 0.01) 

       esttab m1 m2 using Table3.rtf, replace b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap drop(yr*) star(* 0.1 ** 0.05 *** 0.01) title("Table 3 The results of the baseline model")
	  
	  
***Fig.4 The results of the parallel trend test
gen event=year-2014 if treat==1

tab event,gen(eventz)

 forvalue i=1/9{
          replace eventz`i'=0 if eventz`i'==.

}

drop eventz1

 xtreg CEI eventz* $controls yr*,fe cluster(cid)  

   coefplot , coeflabels (eventz2 = "-3"  eventz3 = "-2"  eventz4 = "-1"  eventz5 = "0"   ///
    eventz6 = "1"   ///
    eventz7 = "2"    ///
    eventz8 = "3"    ///
    eventz9 = "4" )    ///
    vertical baselevels keep(*eventz*) yline(0) levels(95)  addplot(line @b @at) ///
	    ciopts(lpattern(dash) recast(rcap) msize(medium)) ///
		 msymbol(circle_hollow)   ///
       scheme(s1mono)  ///
	   yline(0, lwidth(vthin) lpattern(dash) lcolor(blace)) ///
	   xtitle("time", size(small))  ///
	   ylabel(-0.15(0.05)0.15,format(%5.2f) )   

	   
***Fig.5 The results of the placebo test
	forvalue i=1/1000{
    sysuse data, clear //import data
	gen placebo=NPC

    g obs_id= _n
    gen random_digit= runiform()
    sort random_digit
    g random_id= _n
    preserve
        keep random_id placebo
        rename placebo random_placebo
        rename random_id id
        save random_placebo, replace
    restore 
        drop random_digit random_id placebo
        rename obs_id id
        label var id
        save rawdata, replace 

        use rawdata, clear
        xtset cid year
        global controls PGDP PGDP_2 PDEN INDS CONS GOV Lnrain Lnsun
        merge 1:1 id using random_placebo,nogen  
		xtreg CEI i.random_placebo $controls yr*, fe cluster(cid)
        g _b_random_placebo= _b[1.random_placebo]
        g _se_random_placebo= _se[1.random_placebo]
        keep _b_random_placebo _se_random_placebo 
        duplicates drop _b_random_placebo, force
        save placebo`i', replace
    }
    
use placebo1, clear
forvalue i=2/1000{
    replace using placebo`i'
}  
 
forv i=2/1000{
replace using placebo`i'.dta
erase placebo`i'.dta
}
save result_placebo_soedebt_1-1000, replace 

use result_placebo_soedebt_1-1000, clear
gen t=_b_random_placebo/_se_random_placebo
kdensity _b_random_placebo ,normal ytitle("Density") xtitle("Estimated coefficient") saving(a01)
graph export "b-value1000times.png", as(png) name("Graph") replace
kdensity t ,normal  ytitle("Density") xtitle("Estimated t value") saving(a02)

graph combine a01.gph a02.gph, hole(2) r(1) imargin(0 0 0 0) graphregion(margin(l=10 r=10)) title("Placebo test (1000 times)")

   
***Table 4 The results of robustness tests

*(1)PSM-DID
forvalu x=2010/2018{
       preserve
             keep if year==`x'
                 set seed 0001
             psmatch2 treat $controls, outcome(CEI) n(5) ate ties caliper(0.05) common quietly
             drop if _weight==.
             save  psmdid`x'.dta,replace
       restore
}

 preserve 
use psmdid2010.dta ,clear     
forvalu x=2011/2018{
    append using psmdid`x'.dta   
}
  xtreg CEI NPC $controls yr*,fe cluster(cid) 
   est store psm
 restore 
*(2)Use nighttime light data to measure GDP
  xtreg co2_light NPC $controls yr*, fe cluster(cid)     
    est store light
*(3)Substitute dependent variable	
  xtreg co2_mt NPC $controls yr*, fe cluster(cid)   
    est store co2_mt
*(4)Sample adjustment
  xtreg CEI NPC_still $controls yr*, fe cluster(cid)
    est store NPC_still
	
    esttab psm light co2_mt NPC_still, b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle nocon drop(yr* $controls) order(NPC NPC_still) star(* 0.1 ** 0.05 *** 0.01) 

	   esttab psm light co2_mt NPC_still using Table4.rtf, replace b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon order(NPC NPC_still) star(* 0.1 ** 0.05 *** 0.01) title("Table 4 The results of robustness tests")
	

***Table 5 Results of mechanism tests
  xtreg ind_upg NPC $controls yr*, fe cluster(cid)  
    est store ind_upg
  xtreg eco_res NPC $controls yr*, fe cluster(cid)  
    est store eco_res
   esttab ind_upg eco_res, b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) 

    esttab ind_upg eco_res using Table5.rtf, replace b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) title("Table 5 Results of mechanism tests")

	
***Table 6 The analysis of heterogeneity: different population size and resource endowment
  xtreg CEI NPC  $controls  yr* if bigcounty==1 ,fe cluster(cid) 
   est store large
  xtreg CEI NPC  $controls  yr* if bigcounty==0 ,fe cluster(cid) 
   est store small

  xtreg CEI NPC  $controls  yr* if resourcecity==1 ,fe cluster(cid) 
   est store resource
  xtreg CEI NPC  $controls yr*  if resourcecity==0 ,fe cluster(cid) 
   est store non_resource
   
    esttab large small resource non_resource, b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) 
   
     esttab large small resource non_resource using Table6.rtf, replace b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) title("Table 6 The analysis of heterogeneity: different population size and resource endowment")

	 
***Table 7 The analysis of heterogeneity: different low-carbon pilot policy and environmental regulation intensity
  xtreg CEI NPC  $controls yr* if Pilotrt==1 ,fe cluster(cid) 
   est store low_carbon
  xtreg CEI NPC  $controls yr* if Pilotrt==0 ,fe cluster(cid) 
   est store non_low_carbon 

  xtreg CEI NPC  $controls yr*  if erH==1 ,fe cluster(cid) 
   est store erH
  xtreg CEI NPC  $controls yr*  if erH==0 ,fe cluster(cid) 
   est store erL
    
    esttab low_carbon non_low_carbon erH erL, b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) 
   
     esttab low_carbon non_low_carbon erH erL using Table7.rtf, replace b(%9.4f) se(%7.4f) se ar2(%7.4f) nogap mtitle drop(yr* $controls) nocon star(* 0.1 ** 0.05 *** 0.01) title("The analysis of heterogeneity: different low-carbon pilot policy and environmental regulation intensity")

